package com.ljx.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljx.R;
import com.ljx.pojo.EduCourse;
import com.ljx.pojo.EduTeacher;
import com.ljx.service.impl.EduCourseServiceImpl;
import com.ljx.service.impl.EduTeacherServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李加喜
 * @date 2020/10/1 0001 10:45
 * @Email 1129071273@qq.com
 */
@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {
    @Autowired
    private EduTeacherServiceImpl teacherService;
    @Autowired
    private EduCourseServiceImpl courseService;
    //分页显示名师信息
    @PostMapping("getTeacherFront/{current}/{limit}")
    public R getTeacherFront(@PathVariable Long current, @PathVariable Long limit){
        Page<EduTeacher> page = new Page<EduTeacher>(current, limit);
        Map<String,Object> map= teacherService.getTeacherFrontList(page, null);
        //这个换个分页的方式 不用element-ui组件里面的
        //要返回分页里面的所有数据
        return R.ok().data(map);
    }
    //根据Id查询讲师的基本信息
    @GetMapping("/getTeacherById/{teacherId}")
    public R getTeacherById(@PathVariable String teacherId){
        //查询讲师的基本信息
        EduTeacher teacher = teacherService.getById(teacherId);
        //查询讲师所受课程的基本信息
        String id=teacher.getId();
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(wrapper);
        System.out.println(teacher);
        System.out.println(courseList);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
